home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp95 / freyja13.exe / lha / FREYJA.C < prev    next >
C/C++ Source or Header  |  1992-03-22  |  4KB  |  210 lines

  1. /* FREYJA.C -- Freyja Text Editor
  2.  
  3.     Written March 1991 by Craig A. Finseth
  4.     Copyright 1991 by Craig A. Finseth
  5. */
  6.  
  7. #include "freyja.h"
  8.  
  9. void edit();        /* void */
  10.  
  11. /* ------------------------------------------------------------ */
  12.  
  13. #if !defined(SYSMGR)
  14. int
  15. main(argc,argv)
  16.     int argc;
  17.     char *argv[];
  18.     {
  19.     int cnt;
  20.     char screen = '@';
  21.     int size = 128;
  22.     FLAG any = FALSE;
  23.  
  24.     xprintf("Freyja, Copyright 1991,2 by Craig A. Finseth\r\n");
  25.  
  26.     if (argc < 1) {
  27. usage:
  28.         xprintf("usage is: freyja [-options] [<file(s)>]\r\n\
  29.     -z <size>    edit area size in Kbytes\r\n\
  30.     -s <type>    screen type, one of:\r\n\
  31.                 v    vt100\r\n\
  32. %s",
  33. #if defined(UNIX)
  34. "                t    termcap\n"
  35. #else
  36. #if defined(MSDOS)
  37. "                b    bios calls\r\n\
  38.                 m    direct video memory access\r\n"
  39. #else
  40. ""
  41. #endif
  42. #endif
  43.             );
  44.         exit(1);
  45.         }
  46.  
  47. /* arguments */
  48.  
  49.     for (cnt = 1; cnt < argc; cnt++) {
  50.         if (strequ(argv[cnt], "-s")) {        /* set screen type */
  51.             if (++cnt >= argc) {
  52.                 xprintf("Missing screen type.\r\n");
  53.                 goto usage;
  54.                 }
  55.             screen = xtoupper(*argv[cnt]);
  56.             }
  57.         if (strequ(argv[cnt], "-s")) {    /* set buffer size */
  58.             if (++cnt >= argc) {
  59.                 xprintf("Missing buffer size.\r\n");
  60.                 goto usage;
  61.                 }
  62.             if (!SToN(argv[cnt], &size, 10)) {
  63.                 xprintf("Buffer size must be an integer.\r\n");
  64.                 goto usage;
  65.                 }
  66.             }
  67.         else if (*argv[cnt] == '-') {
  68.             xprintf("Unrecognized option '%s'.\n", argv[cnt]);
  69.             goto usage;
  70.             }
  71.         else    ;
  72.         }
  73.  
  74. /* now can initialize stuff */
  75.  
  76.     if (!IniLoad(screen, size)) exit(1);
  77.     TInit();
  78.     if (!BInit(c.g.swap_size)) {
  79.         DError("Can't init buf");
  80.         TFini();
  81.         exit(1);
  82.         }
  83.  
  84.     DInit1();
  85.     cbuf = NULL;
  86.     kill_buf = BBufCreate(SYS_KILL);
  87.  
  88. /* now load files from cmd line */
  89.  
  90.     for (cnt = 1; cnt < argc; cnt++) {
  91.         if (*argv[cnt] == '-') {
  92.             ++cnt;
  93.             }
  94.         else    {
  95.             if (BBufCreate(argv[cnt]) != NULL) BFileRead();
  96.             any = TRUE;
  97.             }
  98.         }
  99.  
  100.     if (!any) {
  101. #else
  102. unsigned int errno;
  103. unsigned int __brklvl;
  104. unsigned char *environ = "";
  105.  
  106. void
  107. main(void)
  108.     {
  109.     JInit();
  110.  
  111.     if (!IniLoad('@', 128)) JFini();
  112.     TInit();
  113.     if (!BInit(c.g.swap_size)) {
  114.         JMsg("Can't init buf");
  115.         JFini();
  116.         }
  117.  
  118.     DInit1();
  119.     cbuf = NULL;
  120.     kill_buf = BBufCreate(SYS_KILL);
  121.  
  122.         {
  123. #endif
  124.         BBufCreate(SYS_SCRATCH);
  125.         BInsStr("Freyja\n\
  126. Copyright 1991,2 by Craig A. Finseth\n\
  127. \n\
  128. Type ^X ^C to exit\n\
  129.      ^X H for help\n\
  130.      ^X H ^C for copying information\n\
  131.      ^X H ^W for warranty information\n\
  132. -------------------------------------\n\
  133.      ^W to clear this text\n");
  134.         }
  135.  
  136.     DInit2();
  137. #if !defined(NOCALC)
  138.     UInit();
  139. #endif
  140.  
  141. #if defined(MSDOS) && !defined(SYSMGR)
  142.     if (c.g.special == 'J') JInit();
  143. #endif
  144.  
  145.     lastkey = 0;
  146.     lasttable = 0;
  147.  
  148.     *stringarg = NUL;
  149.     *filearg = NUL;
  150.  
  151.     DNewDisplay();
  152.  
  153.     edit();            /* do the actual editing */
  154.  
  155. #if defined(SYSMGR)
  156.     JFini();
  157. #else
  158. #if defined(MSDOS)
  159.     if (c.g.special == 'J') JFini();
  160. #endif
  161.     DFini();
  162.     BFini();
  163.     TSetPoint(TMaxRow() - 1,0);
  164.     TFini();
  165. #if defined(MSDOS)
  166.     _exit(0);
  167. #else
  168.     exit(0);
  169. #endif
  170. #endif
  171.     }
  172.  
  173.  
  174. /* ------------------------------------------------------------ */
  175.  
  176. /* This does the actual editing, we assume that the buffer is
  177. initialized. */
  178.  
  179. void
  180. edit()
  181.     {
  182.     struct buffer *lbuf = NULL;
  183.  
  184.     doabort = FALSE;
  185.  
  186.     while (!doabort) {
  187.         if (cbuf->c.fill == 'W') WWrap();
  188.         if (cbuf != lbuf) DModeLine();
  189.         lbuf = cbuf;
  190.  
  191.         DIncrDisplay();
  192.  
  193.         table = 0;
  194.         key = KGetChar();
  195.         uarg = 1;
  196.         isuarg = FALSE;
  197.         isrepeating = FALSE;
  198.         while (uarg > 0) {
  199.             TabDispatch(key, table);
  200.             if (--uarg < 0) uarg = 0;
  201.             isrepeating = TRUE;
  202.             }
  203.         lastkey = key;
  204.         lasttable = table;
  205.         }
  206.     }
  207.  
  208.  
  209. /* end of FREYJA.C -- Freyja Text Editor */
  210.